/**
 * Website
 * 
 * @author: Li Qiang
 */

(function($) {	
	$.fn.extend({
	   	disableContextMenu: function() {
	   		$(this).bind('contextmenu', function(e) {
	   			return false;
	   		});
		}
	});

	$.extend({
		fullScreen: function() {
  			//window.moveTo(0, 0);
  			//window.resizeTo(window.screen.availWidth, window.screen.availHeight);
    	},
    	disableContextMenu: function() {
    		$('html').disableContextMenu();
    	},
		browserHome: function() {
			if (window.home) {
				window.home();
			} else {
				location = "about:home";
			}
		},
		initOptionMenu: function(menuId, open) {
			var id = ( menuId ? menuId : 'optionmenu');
			var menu = $('#'+id);
			var to = '<span><a class="optionmenu-open"  style="height: 48px; width: 16px; text-decoration: none; color: #fff;" href="#"><span>&nbsp;&raquo;&nbsp;</span></a></span>';
			var tc = '<span><a class="optionmenu-close" style="height: 48px; width: 16px; text-decoration: none; color: #fff;" href="#"><span>&laquo;&nbsp;&nbsp;</span></a></span>';
			
			var items = $('a', menu);
			if (items) {
			$(items[0]).before(to);
			$(items[items.length-1]).after(tc);
			var so = $('.optionmenu-open', menu);
			var sc = $('.optionmenu-close', menu);
		
			items.addClass('optionmenu-item');
			$('a > img', menu).addClass('ic48');
			if (open) {
				so.hide();	
				sc.show();
				items.show();
			} else {
				so.show();
				sc.hide();
				items.hide();
			}
					
			so.click(function(e) {	
				so.hide();
				sc.show();
				items.show();
				e.preventDefault();
			});
			sc.click(function(e) {	
				so.show();
				sc.hide();
				items.hide();
				e.preventDefault();
			});
			}
		},
		pathcat: function(path, name) {
			var ends = (path.charAt(path.length - 1) == '/');
			var starts = (name.charAt(0) == '/');
			if (!ends && !starts) {
				return path + "/" + name;
			}
			if (ends && starts) {
				return path + name.substring(1);
			}
			return path + name;
		},
		shorten: function(s, max) {
			if (s && s.length > max) {
				return s.substring(0, max) + "...";
			}
			return s;
		},
		itemIcon: function(o) {
			if (o) {
				if (o.isFile) {
					return $.fileIcon(o.type);
				} else {
					return $.folderIcon(o.name);
				}
			}
			return "/assets/opt/tango-icon-theme/22x22/categories/applications-other.png";
		},
		folderIcon: function() {
			return "/assets/opt/tango-icon-theme/22x22/places/folder.png";
		},
		fileIcon: function(t) {
			var iconpath = "/assets/opt/tango-icon-theme/22x22/";
			var icon = "mimetypes/application-x-executable.png";
			if (t) {
				if (t == "text/html") {
					 icon = "mimetypes/text-html.png";
				}
				if (t.indexOf("text/") == 0) {
					 icon = "mimetypes/text-x-generic.png";
				}
				if (t.indexOf("image/") == 0) {
					 icon = "mimetypes/image-x-generic.png";
				}
				if (t.indexOf("audio/") == 0) {
					 icon =  "mimetypes/audio-x-generic.png";
				}
				if (t.indexOf("video/") == 0) {
					 icon = "mimetypes/video-x-generic.png";
				}
			}
			return iconpath + icon;
		}
	});
})(jQuery);

/**/